package com.zhang.warehouse.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import com.zhang.common.util.time.TimeUtils;
import com.zhang.warehouse.dto.MergeDto;
import com.zhang.warehouse.entity.Purchase;
import com.zhang.warehouse.entity.PurchaseDetail;
import com.zhang.warehouse.mapper.PurchaseDetailMapper;
import com.zhang.warehouse.service.IPurchaseDetailService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zhang.warehouse.service.IPurchaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * <p>
 * 采购需求 服务实现类
 * </p>
 *
 * @author 创世神
 * @since 2023-10-14
 */
@Service
public class PurchaseDetailServiceImpl extends ServiceImpl<PurchaseDetailMapper, PurchaseDetail> implements IPurchaseDetailService {


    @Override
    public R getpurchaseDetailPageList(Map searchDto) {
        QueryWrapper<PurchaseDetail> wrapper = new QueryWrapper<>();
        String pageNum = (String) searchDto.get("pageNum");
        String pageSize = (String) searchDto.get("pageSize");
        String wareId = (String) searchDto.get("wareId");
        if (!StrUtil.isBlank(wareId)) {
            wrapper.eq("ware_id", wareId);
        }
        String status = (String) searchDto.get("status");
        if (!StrUtil.isBlank(status)) {
            wrapper.eq("status", status);
        }
        String searchValue = (String) searchDto.get("searchValue");
        if (!StrUtil.isBlank(searchValue)) {
        }
        if (!(StrUtil.isBlank(pageNum) || StrUtil.isBlank(pageSize))) {
            Page<PurchaseDetail> page = page(new Page<PurchaseDetail>(Integer.valueOf(pageNum), Integer.valueOf(pageSize)), wrapper);
            return RUtils.successData(page);
        }
        List<PurchaseDetail> list = list(wrapper);
        return RUtils.successData(list);
    }



    @Override
    public List<PurchaseDetail> getListByPurchaseId(Long purchaseId) {
        List<PurchaseDetail> list = list(new QueryWrapper<PurchaseDetail>().eq("purchase_id", purchaseId));
        return list;
    }
}
